package com.utils.basejava.concurrent.utils;

import java.util.concurrent.CountDownLatch;

/**
 * 等待多线程完成的CountDownLatch
 * @author XR-8
 *
 */
public class CountDownLatchTest {
	static CountDownLatch c = new CountDownLatch(2);

	public static void main(String[] args) throws InterruptedException {
		new Thread(new Runnable() {
			public void run() {
				System.out.println(1);
				c.countDown();//每调一次countDown方法，则初始值减一
				System.out.println(2);
				c.countDown();//只有当初始值减为0时，才算整个任务完成
//				System.out.println(4);
//				c.countDown();
			}
		}).start();
		c.await();//如果初始值不为零，则会在此处阻塞
		System.out.println("3");
	}
}
